<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Config;
use think\Exception;

/**
 * 招聘信息
 */
class Invite extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    protected $failException = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\api\model\Invite();
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }

    }
    /**
     * 列表
     * @return void
     */
    public function list()
    {
        $input = input();
        try {
            $pageArr = [
                'page' => 1,
                'page_limit' => 30,
            ];
            $where = [];
            if (!empty($input['id'])) {
                $where['id'] = $input['id'];
            }
            if (!empty($input['keyWork'])) {
                $where['name'] = ['like', '%' . $input['keyWork'] . '%'];
            }
            if (!empty($input['district'])) {
                $where['district'] = $input['district'];
            }

            if (!empty($input['district'])) {
                $where['district'] = $input['district'];
            }
            if (!empty($input['city'])) {
                $where['city'] = $input['city'];
            }
            if (!empty($input['money'])) {
                $where['money'] = $input['money'];
            }

            if (!empty($input['money'])) {
                $where['money'] = $input['money'];
            }

            if (!empty($input['province'])) {
                $where['province'] = $input['province'];
            }
            $order = 'm.createtime asc';

            if (!empty($input['type'])){
                if ($input['type'] == 1){
                    $where['is_recommend'] = 2;
                }

                if ($input['type'] == 2){
                    $order = 'm.createtime desc';
                }

//                if ($input['type'] == 3){
//                    $where['address'] = '';
//                }
            }
            $pageArr = array_merge($pageArr, $input);
            $data = $this->model->alias('m')
                ->join('enterprise_user u','u.user_id=m.user_id')
                ->where($where)
                ->order($order)
                ->field('m.*,u.*,u.name as company_name,u.money as company_money')
                ->paginate([
                    'page' => $pageArr['page'] ?: 1,
                    'list_rows' => $pageArr['page_limit'] ?: 10
                ]);
            $this->success('ok', $data);
        }catch (Exception $e) {
            $this->error($e->getMessage());
        }
    }
}